package com.test.demo.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.test.demo.annotation.DataSource;
import com.test.demo.config.DataSourceType;
import com.test.demo.entity.User;
import com.test.demo.mapper.UserMapper;
import com.test.demo.service.UserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Resource
    private UserMapper userMapper;

    @Override
    @DataSource(DataSourceType.MASTER)
    public List<User> getUsersFromMaster() {
        return list();
    }

    @Override
    @DataSource(DataSourceType.SLAVE)
    public List<User> getUsersFromSlave() {
        return list();
    }

    @Override
    @DataSource(DataSourceType.NONE)  // 不指定数据源，根据请求参数判断
    public List<User> get() {
        return userMapper.get();
    }

} 